
package com.qch.springboot_redis.controller;

import com.qch.springboot_redis.clusterConfig.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

/**
 * @Author qch
 * @Date 2021/4/25
 */

@RestController
@RequestMapping(value = "/redis")
public class RedisController {
    @Autowired
    RedisTemplate redisTemplate;
    @Autowired
    private RedisUtil redisUtil;
    @GetMapping("/put")
    public String put(@RequestParam(value = "key")String key,
                      @RequestParam(value = "value")String value)
    {
        //设置数据20秒过期
       // redisTemplate.opsForValue().set(key,value,20,TimeUnit.SECONDS);
        redisUtil.set(key,value);
        return "SUC";
    }
    @GetMapping("/get")
    public String get(@RequestParam(value = "key")String key)
    {
        //设置数据20秒过期
       // Object o = redisTemplate.opsForValue().get(key);
        String s = redisUtil.get(key);
        return s;
    }
}
